package cn.com.connext.scrm.web.rest;

import cn.com.connext.scrm.domain.master.DwaGetCategoryCount;
import cn.com.connext.scrm.domain.master.DwaQuestionRecord;
import cn.com.connext.scrm.service.DwaGetCategoryCountService;
import cn.com.connext.scrm.service.DwaQuestionRecordService;
import cn.com.connext.scrm.service.DwaQuestionnaireService;
import cn.com.connext.scrm.service.dto.JsonResult;
import cn.com.connext.scrm.web.rest.vm.DwaQuestionRecordVM;
import cn.com.connext.scrm.web.rest.vm.DwaQuestionnaireVM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

;

/**
 * 问卷调查
 */
@RestController
@RequestMapping("/api/shopping/dwaGetCategory")
public class DwaGetCategoryCountResource {

    private final Logger log = LoggerFactory.getLogger(DwaGetCategoryCountResource.class);

    @Autowired
    private DwaGetCategoryCountService dwaGetCategoryCountService;



    /**
     * 统计人数次数
     */
    @PostMapping("/addMsg")
    public JsonResult addMsg(@RequestBody DwaGetCategoryCount entity) {
        JsonResult result =new JsonResult();
        try{
            result  = dwaGetCategoryCountService.addMsg(entity);
        }catch (Exception e){
            log.error("e:{}",e.getMessage());
        }
        return result;
    }

    /**
     * 统计人数次数
     */
    @PostMapping("/findAllCount")
    public JsonResult findAllCount() {
        JsonResult result =new JsonResult();
        Map<String,Object> map = new HashMap<>();
        try{
                List<DwaGetCategoryCount> list  = dwaGetCategoryCountService.findAll();
                map.put("allCount",list.size());
                List<String> norepeatCountList =  dwaGetCategoryCountService.findUserCount();
                map.put("norepeatCount",norepeatCountList.size());
        }catch (Exception e){
            log.error("e:{}",e.getMessage());
        }
        result.setData(map);
        result.setState(0);
        result.setMessage("数据如上");
        return result;
    }

}
